// pages/card_voucher/conversion/conversion.js
Page({
  data: {
    detailShow:true,
  },
  okBtn: function(e) {
    console.log(e.detail.value.dhcode)
    let ducode = e.detail.value.dhcode
    // return false
    let that = this
    // that.setData({
    //   ducode: ducode
    // })
    getApp().request({
      url: getApp().api.cardshop.invite_gift_card,
      data: {
        code: ducode
      },
      success: function(t) {
        console.log(t)
        if (t.code == 0) {
          that.setData({
            details: t.data,
            detailShow:false
          })
        }else{
          wx.showModal({
            cancelText:"返回首页",
            confirmText:"重新填写",
            content: t.msg,
            success:res=>{
              if(res.cancel==true){
                wx.redirectTo({
                  url: '/pages/index/index'
                })
              }
            }
          })
        }
        
      }
    });
  },

  // 领取 兑换码所显示卡
  getTheCard: function() {
    let that = this
    let card_id = that.data.details.id
    // ReceiveGiftCards
    getApp().request({
      url: getApp().api.cardshop.receive_gift_cards,
      data: {
        card_id: card_id
      },
      success: function(t) {
        console.log(t)
        wx.showModal({
          content: t.msg,
          showCancel: true,
          cancelText: '返回首页',          
          confirmText: '查看卡片',          
          success: function(res) {
            if(res.confirm==true){
              wx.redirectTo({
                url: '/pages/card_package/index'
              })
            }else{
              wx.redirectTo({
                url: '/pages/index/index'
              })
            }
          }
        })
      }
    });
  },


  onLoad: function(options) {

  },
  onReady: function() {

  },
  onShow: function() {

  },
  onHide: function() {

  },
  onUnload: function() {

  },
  onPullDownRefresh: function() {

  },
  onReachBottom: function() {

  },
  onShareAppMessage: function() {

  }
})